package com.ruoyi.project.module.rimen.controller;

import java.util.List;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.project.module.movie.domain.Movie;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.module.rimen.domain.Rimen;
import com.ruoyi.project.module.rimen.service.IRimenService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;

/**
 * 电影链接 信息操作处理
 * 
 * @author ruoyi
 * @date 2018-11-26
 */
@Controller
@RequestMapping("/module/rimen")
public class RimenController extends BaseController
{
    private String prefix = "module/rimen";
	
	@Autowired
	private IRimenService rimenService;
	
	@RequiresPermissions("module:rimen:view")
	@GetMapping()
	public String rimen()
	{
	    return prefix + "/rimen";
	}
	
	/**
	 * 查询电影链接列表
	 */
	@RequiresPermissions("module:rimen:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Rimen rimen)
	{
		startPage();
        List<Rimen> list = rimenService.selectRimenList(rimen);
		return getDataTable(list);
	}
	
	/**
	 * 新增电影链接
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存电影链接
	 */
	@RequiresPermissions("module:rimen:add")
	@Log(title = "电影链接", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Rimen rimen)
	{		
		return toAjax(rimenService.insertRimen(rimen));
	}

	/**
	 * 修改电影链接
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		Rimen rimen = rimenService.selectRimenById(id);
		mmap.put("rimen", rimen);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存电影链接
	 */
	@RequiresPermissions("module:rimen:edit")
	@Log(title = "电影链接", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Rimen rimen)
	{		
		return toAjax(rimenService.updateRimen(rimen));
	}
	
	/**
	 * 删除电影链接
	 */
	@RequiresPermissions("module:rimen:remove")
	@Log(title = "电影链接", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(rimenService.deleteRimenByIds(ids));
	}

	@Log(title = "電影連接信息", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	@ResponseBody
	public AjaxResult export(Rimen rimen) throws Exception
	{

		try
		{
			List<Rimen> list = rimenService.selectRimenList(rimen);
			ExcelUtil<Rimen> util = new ExcelUtil<Rimen>(Rimen.class);
			return util.exportExcel(list, "rimen");
		}
		catch (Exception e)
		{
			return error("导出Excel失败，请联系网站管理员！");
		}
	}

}
